package com.qf.common.core.config;

import com.qf.common.core.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * ---厚德载物---
 *
 * @Author wangbo
 * @Date 2024/10/14
 * @Desc 人的一生适可而止
 */
@Configuration // 这个注解,让springboot框架知道,以下的这个类是提供配置
public class MyWebMvcInterceptorConfig implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        // addPathPatterns 定义拦截的路径
        // excludePathPatterns 定义放行的路径
        String[] excludePatterns = new String[]{
                "/swagger-resources/**",
                "/webjars/**",
                "/v3/**",
                "/error",
                "/swagger-ui.html",
                "/swagger-ui/**",
                "/api-docs/**",
                "/doc.html",
                "/error",
                "/food/selectAll",
                "/sys/user/login"};

        registry.addInterceptor(new LoginInterceptor())
                .addPathPatterns("/**")//拦截所有
                .excludePathPatterns(excludePatterns);
    }
}
